package com.zby.demo.config;

import com.zby.demo.filter.LoginFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author ChrisPhantom
 * @CreateDate 2020/12/13 23:40
 */
@Configuration
public class FilterConfig {
    @Value("${pathList}")
    String pathList;

    /*
     * @Param: []
     * @Return: org.springframework.boot.web.servlet.FilterRegistrationBean
     * @Author: ChrisPhantom
     * @Date: 2020/12/24 10:59
     * @Description: 未登录进页面需先登录，已登录再进登录页面不需要再次登录，学生登录时进其他（教师、管理员）页面会跳到学生界面，教师、管理员同理。
     */
    @Bean
    public FilterRegistrationBean registLoginFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new LoginFilter());
        registration.addUrlPatterns("/front/*", "/back/*");
        registration.addInitParameter("paths", pathList);
        registration.setName("LoginFilter");
        registration.setOrder(1);
        return registration;
    }

}
